package com.yanqu.road.server.cmd.cross.marriage;

import com.yanqu.road.entity.marriage.CrossMarriageResult;
import com.yanqu.road.entity.marriage.MarriageInfo;
import com.yanqu.road.logic.pb.MarriagePb;
import com.yanqu.road.pb.marriage.CrossMarriageProto;
import com.yanqu.road.server.cmd.base.AbstractServerCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.manger.marriage.MarriageMgr;
import com.yanqu.road.server.manger.player.GamePlayerMgr;
import com.yanqu.road.utils.YanQuMessageUtils;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.Protocol;


@Cmd(code = Protocol.S_CROSS_UNION_MARRIAGE_TO_PARTNER_DEAL_AGREE, desc = "到对方服务器处理同意商会联姻")
public class CrossUnionMarriageToPartnerDealAgreeCmd extends AbstractServerCommand {
	private long partnerUserId;
	private String partnerChildUid;
	private MarriageInfo marriageInfo;

	@Override
	public boolean parseData(YanQuMessage packet) throws Exception {
		CrossMarriageProto.CrossMarriageAgreeCrossDealReqMsg reqMsg = CrossMarriageProto.CrossMarriageAgreeCrossDealReqMsg.parseFrom(packet.getBytes());
		marriageInfo = MarriagePb.parseMarriageInfo(reqMsg.getApplyData());
		partnerChildUid = reqMsg.getPartnerChildUid();
		partnerUserId = packet.getPlayerId();
		return true;
	}

	@Override
	public void execute(YanQuMessage packet) throws Exception {
		CrossMarriageResult marriageResult = MarriageMgr.toPartnerDealUnionAgree(marriageInfo, partnerUserId, partnerChildUid);
		CrossMarriageProto.CrossMarriageAgreeCrossDealRespMsg.Builder respMsg = CrossMarriageProto.CrossMarriageAgreeCrossDealRespMsg.newBuilder();
		respMsg.setRet(marriageResult.getRet());
		respMsg.setApplyData(MarriagePb.parseMarriageApplyTempMsg(marriageInfo));
		if(0 == marriageResult.getRet()){
			respMsg.setPartnerData(MarriagePb.parseMarriageApplyTempMsg(marriageResult.getMarriageInfo()));
		}
		YanQuMessage pbMsg = YanQuMessageUtils.buildMessage(Protocol.C_AGREE_UNION_MARRIAGE_TO_PARTNER_DEAL_RESP, respMsg);
		GamePlayerMgr.sendPacket(0, pbMsg);
	}

	@Override
	public void sendData(YanQuMessage packet) throws Exception {

	}
}
